﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SCRUM.Core.BusinessObjects
{
    /// <summary>
    /// Business object for widget.
    /// </summary>
    [Serializable()]
    public class Widget : BusinessObject
    {
        /// <summary>
        /// Column that contains this widget.
        /// </summary>
        private WidgetColumn column;

        /// <summary>
        /// Initializes a new instance of the <see cref="Widget"/> class.
        /// </summary>
        public Widget()
            :base(-1)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Widget"/> class.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <param name="type">The type of the widget.</param>
        /// <param name="order">The order of the widget in column.</param>
        /// <param name="typeID">The type ID.</param>
        public Widget(int id, string type, int order, int typeID)
            :base(id)
        {
            this.ID = id;
            this.Type = type;
            this.TypeToDisplay = this.LocalizeString("WidgetTypeTitle", type);
            this.Order = order;
            this.TypeID = typeID;
        }

        public string TypeToDisplay { get; set; }

        /// <summary>
        /// Gets or sets the type. 
        /// </summary>
        /// <remarks>
        /// Type value has to be the same as name of the widget in SCRUM.Web/Widgets folder.
        /// </remarks>
        /// <value>The type of the widget.</value>
        public string Type { get; set; }

        /// <summary>
        /// Gets or sets the type of the widget.
        /// </summary>
        /// <value>The type of the widget.</value>
        public int TypeID { get; set; }

        /// <summary>
        /// Gets or sets the order.
        /// </summary>
        /// <value>The order.</value>
        public int Order { get; set; }

        /// <summary>
        /// Gets or sets the column.
        /// </summary>
        /// <value>The column.</value>
        public WidgetColumn Column
        {
            get
            {
                // Lazy loading.
                if (this.column == null)
                {
                    this.column = DAO.DAOWidgetColumn.GetColumn(this);
                }
                return this.column;
            }
            set
            {
                this.column = value;
            }
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            return String.Format("ID={0}, Type={1}, Order={2}", this.ID, this.Type, this.Order);
        }
    }
}
